package edu.hit.pact.pgse.crawler.bbs;

import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class TianYaBBSURL extends BBSURL{

 	String type; //iditem or stritem
 	String subitem;
    int pageno =0;
    Date date;
    String part;
    String strsubitem;
    String strsubitem2;
   

	/*
     * pageno=2&stritem=free&part=0&nextarticle=2010%2D11%2D5+13%3A13%3A25&strsubitem=&strsubitem2=
     * 此些变量均是按照天涯论坛的域名设定
	*/
    
    public TianYaBBSURL() {
		super();
	}
    
    
	public TianYaBBSURL(URL url) {
		super(url);
		// TODO Auto-generated constructor stub
	}


	public TianYaBBSURL(String type) {
		super();
		this.type = type;
	}

	public TianYaBBSURL(URL url,String type) {
		super(url);
		this.type = type;
	}
	
	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	
	public int getPageno() {
		return pageno;
	}

	public void setPageno(int pageno) {
		this.pageno = pageno;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getPart() {
		return part;
	}

	public void setPart(String part) {
		this.part = part;
	}

	public String getStrsubitem() {
		return strsubitem;
	}

	public void setStrsubitem(String strsubitem) {
		this.strsubitem = strsubitem;
	}
	
	public void fllter() {
		// TODO Auto-generated method stub
		this.extractQuery();
		this.extractPath();
		Map map = this.getParams();
		if(map.containsKey("iditem")){
			type = "iditem";
		}else{
			type = "stritem";
		}
		if(map.containsKey(type)){
			subitem = (String) map.get(type);
		}else {
			String[] paths = getPaths();
			String[] items = paths[paths.length-1].split("\\.");
			if(items != null)
				subitem = items[0];
			else subitem = "empty";
			System.out.println("now topic is " + subitem);
		}
		if(map.containsKey("pageno")){
			pageno = Integer.parseInt((String) map.get("pageno"));
		}
		else pageno = 1;
		if(map.containsKey("Date")){
			
		}
		if(map.containsKey("part")){
			part = (String) map.get("part");
		}
		if(map.containsKey("strsubitem")){
			strsubitem = (String) map.get("strsubitem");
		}
		if(map.containsKey("strsubitem2")){
			strsubitem2 = (String) map.get("strsubitem2");
		}
	}
	

	public String getSubitem() {
		return subitem;
	}

	public void setSubitem(String subitem) {
		this.subitem = subitem;
	}

	public String getStrsubitem2() {
		return strsubitem2;
	}

	public void setStrsubitem2(String strsubitem2) {
		this.strsubitem2 = strsubitem2;
	}

}
